/**
 * problem_021.c
 * Copyright (C) 2011-03-19 - xrose
 * Evaluate the sum of all the amicable numbers under 10000
 */

#include <stdio.h>
#include <math.h>
#define m_ami 10000

int isAmi(int _ami);
int sod(int _snumb);
int main (int argc, char *argv[])
{
    int i;
    int sum = 0;
    printf("__%d\n", sod(284));
    for(i=1; i<m_ami; i++)
    {
        if(isAmi(i))
        {
            printf("%d is an amicable number\n", i);
            sum+=i;
        }
    }
    printf("Answer is %d\n", sum);
    return 0;
}
int isAmi(int _ami)
{
    int sod_ami = sod(_ami);
    if((sod(sod_ami) == _ami)&&(_ami != sod_ami))
    {
        return 1;
    } else
    {
        return 0;
    }
}
/*Sum of all divisors of a number*/
int sod(int _snumb)
{
    int _sq = floor(_snumb/2);
    int i;
    int s_divisor = 1;
    if(_snumb <=1)
    {
        s_divisor = 0;
    }
    for(i = 2; i<=_sq; i++)
    {
        if(_snumb%i == 0)
        {
            s_divisor +=i;
        }
    }
    return s_divisor;
}
